﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shsc.Net.Common.Validator.Validators;

namespace Shsc.Net.Common.Validator.Attributes
{
    /// <summary>
    /// 数字范围Check
    /// </summary>
    [AttributeUsage(AttributeTargets.Property)]
    public class RangeAttribute : BaseValidationAttribute
    {

        /// <summary>
        /// 
        /// </summary>
        private string ERROR_MESSAGE_ID = "HE_90004";

        /// <summary>
        /// 最大值
        /// </summary>
        public long Max { get; set; }

        /// <summary>
        /// 最小值
        /// </summary>
        public long Min { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        public RangeAttribute(long min, long max)
        {
            Min = min;
            Max = max;
            this.ErrorMessageId = ERROR_MESSAGE_ID;
        }

        /// <summary>
        /// 创建验证器
        /// </summary>
        /// <returns></returns>
        protected override BaseValidator CreateValidator()
        {
            if (ErrorMessageParam == null
                || ErrorMessageParam.Length == 0)
            {
                this.ErrorMessageParam = new string[] { Convert.ToString(Min),
                Convert.ToString(Max)};
            }
            return new RangeValidator();
        }
    }
}
